// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database()
const _ = db.command
const $ = db.command.aggregate

/**
 * 查询公告的申请或线索
 */
exports.main = async (event, context) => {
  const { OPENID } = cloud.getWXContext()
  const noticeId = event.noticeId
  return await db.collection('request')
    .where({ notice_id: noticeId })
    .orderBy('tosee', 'desc')
    .orderBy('create', 'desc')
    .get()
}